/**
 * 解析url参数
 * @example ?id=12345&a=b
 * @return Object {id:12345,a:b}
 */
export function urlParse() {
  let url = window.location.search; // "?id=2222&a=b/goods"
  let obj = {};
  let reg = /[?&][^?&]+=[^?&]+/g;
  let arr = url.match(reg); // ['?id=12345', '&a=b']
  if (arr) {
    arr.forEach((item) => {
      let tempArr = item.substring(1).split('='); // 将每一项从“=” 切开 ["id", "2222"] ["a", "b"]
      let key = decodeURIComponent(tempArr[0]); // id  a  将json转义成字符串
      let val = decodeURIComponent(tempArr[1]); // 222 b
      obj[key] = val; // {id: "222", a: "b"}
    });
  }
  return obj;
};
